#pragma once

#include <iostream>
#include "Platform.h"
using namespace std;



 enum E_OBJECT_TYPE 
 { 
     XOBJECT = 1, 
     IOCPMEM_BUFF, 
	 INSIDE_MSG,
	 OUTSIDE_MSG,
	 EVENT,
     CONNECT_CHANNEL_REBOT, 
	 CONFIGER_ROBOT,
	 NETMANAGER_ROBOT,
	 MANAGER_ROBOT,

 };

 

class XObject
{
public:
	XObject(void);
	virtual ~XObject(void);

	virtual void Updata();
	virtual void OnTime(long long llTimeBegin);
	virtual void PrintInfo();
	//CObject::IsKindOf()
public:

#ifdef WIN32
	long long  objID;
	long	   handleID;
#else
	long long objID;
	long	   handleID;
#endif

	E_OBJECT_TYPE objType;
	string        objName;
	string		  m_lpszClassName;

	long long     m_llLastOnTime;

	//--------------test-------------
	int  keepLive;
};

#ifndef DYNCREATE_H_  
#define DYNCREATE_H_  
  
#include <map>  
#include <string>  
  
#define DECLARE_DYNBASE(base)   \
public: \
    typedef base* (*class_creator)(); \
    static base* create(const std::string& class_name); \
    static std::map<const std::string,class_creator>& get_class_set(){ \
    static std::map<const std::string,class_creator> class_set; \
    return class_set;} \
    struct _auto_register { \
	_auto_register(const std::string& name, base::class_creator creator){ \
        base::get_class_set().insert(std::pair<const std::string,base::class_creator>(name,creator));}};  
  
#define IMPLEMENT_DYNBASE(base) \
    base* base::create(const std::string& class_name){ \
        std::map<const std::string,base::class_creator>::iterator it; \
        it = get_class_set().find(class_name); \
        if(it != get_class_set().end()){ \
            return (it->second)();} \
        return NULL; }
  
#define DECLARE_DYNCREATE(derived,base) \
public: \
    static base* create(){ return (base*)(new derived); }  
  
#define IMPLEMENT_DYNCREATE(derived) \
    static derived::_auto_register _register_##derived(#derived,derived::create);   
#endif

struct CRuntimeClass
{
   // Attributes
    LPCSTR m_lpszClassName;
    int m_nObjectSize;
    UINT m_wSchema; // schema number of the loaded class
    XObject* (PASCAL* m_pfnCreateObject)(); // NULL => abstract class
	

    #ifdef _AFXDLL
    CRuntimeClass* (PASCAL* m_pfnGetBaseClass)();
    #else
    CRuntimeClass* m_pBaseClass; 
    #endif

   // Operations
    XObject* CreateObject()
	{
		return NULL;
	}

    bool IsDerivedFrom(const CRuntimeClass* pBaseClass) const
	{
		return true;
	}

   // Implementation
   // void Store(CArchive& ar) const;
   // static CRuntimeClass* PASCAL Load(CArchive& ar, UINT* pwSchemaNum);

   // CRuntimeClass objects linked together in simple list
   CRuntimeClass* m_pNextClass; // linked list of registered classes
};
